package com.zxh.servlet;



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class test {
    public static void main(String[] args) {
        // 数据库连接信息
        String url = "jdbc:mysql://localhost:3306/smbms";
        String username = "root";
        String password = "123456";

        try {
            // 加载 MySQL 驱动类
            Class.forName("com.mysql.jdbc.Driver");

            // 建立数据库连接
            Connection connection = DriverManager.getConnection(url, username, password);

            // 创建 Statement 对象
            Statement statement = connection.createStatement();

            // 执行查询语句
            String sql = "SELECT * FROM smbms_user";
            ResultSet resultSet = statement.executeQuery(sql);

            // 处理结果集
            while (resultSet.next()) {
                // 假设表中有 id 和 name 两列
                int id = resultSet.getInt("id");
                String name = resultSet.getString("userCode");
                System.out.println("ID: " + id + ", Name: " + name);
            }

            // 关闭资源
            resultSet.close();
            statement.close();
            connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}